package com.corechina.apex_osswords.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.corechina.apex_osswords.common.Response;
import com.corechina.apex_osswords.domain.entity.SysLogs;
import com.corechina.apex_osswords.domain.dao.SysLogsMapper;
import com.corechina.apex_osswords.domain.vo.SysLogsVo;
import com.corechina.apex_osswords.service.ISysLogsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 系统日志表 服务实现类
 * </p>
 *
 * @author cc
 * @since 2022-03-03
 */
@Service
public class SysLogsServiceImpl extends ServiceImpl<SysLogsMapper, SysLogs> implements ISysLogsService {

    @Autowired
    private SysLogsMapper sysLogsMapper;

    @Override
    public Response add(SysLogs sysLogs) {
        sysLogsMapper.insert(sysLogs);
        return Response.ok();
    }

    @Override
    public Response getAllSysLogs(Integer operator, String ip, String operation, String beginTime, String endTime, Integer pageIndex, Integer pageSize) {
        IPage<SysLogsVo> sysLogsVo = sysLogsMapper.getAllSysLogs(new Page<>(pageIndex, pageSize), operator, ip, operation, beginTime, endTime);
        return Response.ok(sysLogsVo.getRecords(), sysLogsVo.getTotal());
    }

}
